package com.blog4j.server.modules.email.controller;

import cn.dev33.satoken.annotation.SaCheckLogin;
import com.blog4j.common.annotation.OperationLog;
import com.blog4j.common.enums.ModuleTypeEnum;
import com.blog4j.common.enums.OperationTypeEnum;
import com.blog4j.common.model.Result;
import com.blog4j.requestRate.annotation.RequestRate;
import com.blog4j.server.modules.email.service.EmailService;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author 98k灬
 * @version v1.0.0
 * @Description : 功能描述
 * @Create on : 2024/8/8 21:06
 **/
@RestController
@RequestMapping("/email")
@RequiredArgsConstructor(onConstructor_ = @Autowired)
public class EmailController {
    private final EmailService emailService;

    /**
     * 发送邮件验证码
     *
     * @param email 邮件
     * @return 发送成功
     */
    @RequestRate(count = 5)
    @OperationLog(operationType= OperationTypeEnum.INSERT,
            module= ModuleTypeEnum.EMAIL,
            description = "发送邮件验证码")
    @SaCheckLogin
    @GetMapping("/sendEmail")
    public Result sendEmail(@RequestParam("email") String email) {
        emailService.sendSystemEmail(email);
        return Result.ok();
    }
}
